﻿@using Project.Domain.Entities
@using Project.Resource.Sports
@using Project.Resource.Template
@{
    ViewBag.Title = "Create Your betting";
    var culture = "";
    if (Session["Culture"] != null && Session["Culture"].ToString().Equals("vi-VN"))
    {
        culture = "vi-VN";
    }
}
    
<section class="container clearfix">
    <div class="left_content">
        <div id="deposit_ajax">

        </div>
        <div id="withdraw_ajax">

        </div>
        <script type="text/javascript">
            $(document).ready(function () {
                LoadDepositAjax(root, "ListDeposit", 1);
                LoadWithDrawAjax(root, "ListWithdraw", 1);
            });
        </script>        
        <div class="clearAll"></div>            
    </div>  
    
    <div class="info" style="width: 488px; margin-right: 15px; margin-left: 2px;">
        <div class="titleleague" style="color: #01B3F1;">
            Create Your betting
        </div>
        <div class="clearAll"></div>
        <div class="notes_create">
            <div style="padding:5px; font-size:16px; font-weight:bold; color:#3C9A01;">                
                <span>@Html.Raw(ViewBag.TitleNotes)</span>                      
            </div>        
            @foreach (var item in (IEnumerable<Common>)ViewBag.Notes)
            {
                <div style="width: 100%; padding-bottom:5px; color: #505050;">
                    <span>
                        
                        @if (culture.Equals("vi-VN"))
                        {                           
                            <img src="@Url.Content("~/Content/images/icons/check_16x16.png")" alt="" />
                            <span>@Html.Raw(item.Content)</span>
                                    
                        }
                        else
                        {
                            <img src="@Url.Content("~/Content/images/icons/check_16x16.png")" alt="" />
                            <span>@Html.Raw(item.ContentEn)</span>                                                                
                        }                                   
                    </span>
                </div>
            }
        </div>

        <div class="notes_create">
            <div style="padding: 5px; font-size: 16px; font-weight: bold;color: #3C9A01;">
                <span>@Html.Raw(ViewBag.TitleNotes)</span>
            </div> 
            <div class="makebet_zone_form">                    
                @using (Html.BeginForm("NewBet", "sport", FormMethod.Post, new { @id = "formbets" }))
                {
                    @Html.ValidationSummary()
                    <div id="ListLeague" style="float: left;">
                        <div class="ListLeague_title">                            
                            @BetResource.SelectLeague
                        </div>
                        <div class="ListLeague_dropdow">   
                            <input type="hidden" value="" id="LeagueID_hiden" />                            
                            <select id="LeagueID" name="LeagueID" class="dropdowlist_bet">							
                            </select>
                        </div>			   
                    </div>			        
                    <div id="ListHometeam" style="float: left;">
                        <div class="ListLeague_title">                            
                            @BetResource.SelectHomeTeam
                        </div>
                        <div class="ListLeague_dropdow">
                            <select id="HomeTeamID" name="HomeTeamID" class="dropdowlist_bet">
                                <option value="0">@BetResource.SelectHomeTeam</option>
                            </select>
                        </div>
                    </div>
			
                    <div id="ListAwayteam" style="float: left;">
                        <div class="ListLeague_title">                            
                            @BetResource.SelectAwayTeam
                        </div>
                        <div class="ListLeague_dropdow">
                            <select id="AwayTeamID" name="AwayTeamID" class="dropdowlist_bet">
                                <option value="0">@BetResource.SelectAwayTeam</option>
                            </select>
                        </div>

                    </div>
			
                    <div id="Listcategory" style="float: left;">
                        <div class="ListLeague_title" style="text-align: left;">
                            @BetResource.SelectTypeOdds
                        </div>
                        <div class="ListLeague_dropdow" style="float: left;">                    
                            <select id="CategoryID" name="CategoryID" class="dropdowlist_bet">
                                <option value="1" selected="selected">3way</option>
                                <option value="2">Handicap</option>
                                <option value="3">Asian Handicap</option>
                                <option value="4">Under-Over</option>
                                <option value="5">Exact Score</option>
                            </select>      
                        </div>                   
                    </div>
                    <div class="ClearAll"></div>                    
                    <div id= "oddsoption">
			   
                    </div>
                }
            </div>   
        </div>
    </div>

    <div id="content_right" style="float: left;">
        <div id="match_result">                   
        </div>

        <div class="clearAll"></div>  

        <div id="match_inplay">            
        </div>                                       
    </div>
</section>

<div id="oddsHome_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.OddsHome
</div>
<div id="oddsAway_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.OddsAway
</div>
<div id="oddsDraw_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.OddsDraw
</div>
<div id="Maximumbet_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.Maxbet
</div>
<div id="ScoreHandicapHome_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.ScoreHandicapHome
</div>
<div id="ScoreHandicapAway_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.ScoreHandicapAway
</div>
<div id="NewBetFailed" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.NewBetFailed
</div>
<div id="ErrorSelectLeague" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.ErrorSelectLeague
</div>
<div id="oddsUnder_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.OddsUnder
</div>
<div id="oddsOver_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.OddsOver
</div>
<div id="RateUnderOver_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.RateUnderOver
</div>
<div id="OddsExact_pp" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.OddsExact
</div>
<div id="CheckBalance" title="@TemplateResource.Invalid" style="display: none;">
    @BetResource.CheckBalance
</div>

<div id="NewBetSuccessfully" title="@TemplateResource.Successfully" style="display: none;">
    @BetResource.NewBetSuccessfully
</div>


<script type="text/javascript">
    $(document).ready(function () {        
        getMatchInPlay();
        getMatchResult();       
        setInterval(function () {
            getMatchResult(), getMatchInPlay();
        }, 50000);
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $.post('@Url.Action("GetAllLeague", "Sport")', function (data) {
            $("#LeagueID").html(data);
        });

        $.post('@Url.Action("changehtmlodds", "Sport")', { categoryid: 1 }, function (data) {
            $("#oddsoption").html(data);
            return false;
        });
    });
    $("#LeagueID").change(function () {
        var id = $(this).attr('value');
        if (id == 0) {
            return false;
        }
        $.post('@Url.Action("GetHometeam", "Sport")', { leagueId: id }, function (data) {
            $("#HomeTeamID").html(data);
            return false;
        });
        $.post('@Url.Action("GetAwayteam", "Sport")', { leagueId: id }, function (data) {
            $("#AwayTeamID").html(data);
            return false;
        });
    });
    
    $("#HomeTeamID").change(function () {
        var id = $(this).attr('value');
        var leagueid = $("#LeagueID").attr('value');
        if (leagueid == 0) {
            return false;
        }
        $.post('@Url.Action("Getawaybyhome", "Sport")', { hometeamid: id, leagueid: leagueid }, function (data) {
            $("#AwayTeamID").html(data);
            return false;
        });
    });
    $("#AwayTeamID").change(function () {
        var id = $(this).attr('value');
        var leagueid = $("#LeagueID").attr('value');
        if (leagueid == 0) {
            return false;
        }
        $.post('@Url.Action("gethomebyaway", "Sport")', { awayteamid: id, leagueid: leagueid }, function (data) {
            $("#HomeTeamID").html(data);
            return false;
        });
    });
    
    $("#CategoryID").change(function () {
        var categoryid = $(this).attr('value');
        $.post('@Url.Action("changehtmlodds", "Sport")', { categoryid: categoryid }, function (data) {
            $("#oddsoption").html(data);
            return false;
        });
    });

    $('input[type=reset]').click(function () {
        $.post('@Url.Action("changehtmlodds","Sport")', { categoryid: 1 }, function (data) {
            $("#oddsoption").html(data);
            return false;
        });
    });
</Script>    
<script>
    function isNumberKey(kpress) {
        var charCode = (kpress.which) ? kpress.which : event.keyCode;
        if (charCode > 31 && (charCode < 48 || (charCode > 57 && charCode != 190)))
            return false;
        return true;
    }

    function checknewbet(sender) {
        var leagueid = $("#LeagueID").attr('id');
        if (leagueid > 0 && leagueid != isNaN) {
            return true;
        } else {
            return false;
        }
    }

    $("#formbets").submit(function (event) {
        event.preventDefault();
        var leagueId = $("#LeagueID").attr('value');
        var homeTeamId = $("#HomeTeamID").attr('value');
        var awayTeamId = $("#AwayTeamID").attr('value');
        var categoryId = $("#CategoryID").attr('value');
        var oddshome = $("#oddshome").attr('value');
        var oddsdraw = $("#oddsdraw").attr('value');
        var oddsaway = $("#oddsaway").attr('value');
        var oddsmax = $("#oddsmax").attr('value');
        var scorehome = $("#scorehome").attr('value');
        var scoreaway = $("#scoreaway").attr('value');
        var rateunderover = $("#rateunderover").attr('value');
        var oddsunder = $("#oddsunder").attr('value');
        var oddsover = $("#oddsover").attr('value');
        var oddsexact = $("#oddsexact").attr('value');
        if (leagueId == 0) {
            popupSite("ErrorSelectLeague");
            $("#LeagueID").focus();
            return false;
        }
        if (categoryId == 1) {
            if (isNaN(oddshome) || oddshome <= 0) {
                popupSite("oddsHome_pp");
                $("#oddshome").val('');
                $("#oddshome").focus();
                return false;
            }

            if (isNaN(oddsdraw) || oddsdraw <= 0) {
                popupSite("oddsDraw_pp");
                $("#oddsdraw").val('');
                $("#oddsdraw").focus();
                return false;
            }

            if (isNaN(oddsaway) || oddsaway <= 0) {
                popupSite("oddsAway_pp");
                $("#oddsaway").val('');
                $("#oddsaway").focus();
                return false;
            }

            if (isNaN(oddsmax) || oddsmax <= 0) {
                popupSite("Maximumbet_pp");
                $("#oddsmax").val('');
                $("#oddsmax").focus();
                return false;
            }
        }
        if (categoryId == 2) {

            if (isNaN(oddshome) || oddshome <= 0) {
                popupSite("oddsHome_pp");
                $("#oddshome").val('');
                $("#oddshome").focus();
                return false;
            }

            if (isNaN(oddsdraw) || oddsdraw <= 0) {
                popupSite("oddsDraw_pp");
                $("#oddsdraw").focus();
                return false;
            }

            if (isNaN(oddsaway) || oddsaway <= 0) {
                popupSite("oddsAway_pp");
                $("#oddsaway").val('');
                $("#oddsaway").focus();
                return false;
            }

            if (isNaN(scorehome) || scorehome < 0) {
                popupSite("ScoreHandicapHome_pp");
                $("#scorehome").val('');
                $("#scorehome").focus();
                return false;
            }

            if (isNaN(scoreaway) || scoreaway < 0) {
                popupSite("ScoreHandicapAway_pp");
                $("#scoreaway").val('');
                $("#scoreaway").focus('');
                return false;
            }
            if (isNaN(oddsmax) || oddsmax <= 0) {
                popupSite("Maximumbet_pp");
                $("#oddsmax").val('');
                $("#oddsmax").focus();
                return false;
            }
        }
        if (categoryId == 3) {

            if (isNaN(oddshome) || oddshome <= 0) {
                popupSite("oddsHome_pp");
                $("#oddshome").val('');
                $("#oddshome").focus();
                return false;
            }

            if (isNaN(oddsaway) || oddsaway <= 0) {
                popupSite("oddsAway_pp");
                $("#oddsaway").val('');
                $("#oddsaway").focus();
                return false;
            }

            if (isNaN(scorehome) || scorehome < 0) {
                popupSite("ScoreHandicapHome_pp");
                $("#scorehome").val('');
                $("#scorehome").focus();
                return false;
            }

            if (isNaN(scoreaway) || scoreaway < 0) {
                popupSite("ScoreHandicapAway_pp");
                $("#scoreaway").val('');
                $("#scoreaway").focus();
                return false;
            }
            if (isNaN(oddsmax) || oddsmax <= 0) {
                popupSite("Maximumbet_pp");
                $("#oddsmax").val('');
                $("#oddsmax").focus();
                return false;
            }
        }

        if (categoryId == 4) {

            if (isNaN(rateunderover) || rateunderover <= 0) {
                popupSite("RateUnderOver_pp");
                $("#rateunderover").val('');
                $("#rateunderover").focus();
                return false;
            }

            if (isNaN(oddsunder) || oddsunder <= 0) {
                popupSite("oddsUnder_pp");
                $("#oddsunder").val('');
                $("#oddsunder").focus();
                return false;
            }

            if (isNaN(oddsover) || oddsover <= 0) {
                popupSite("oddsOver_pp");
                $("#oddsunder").val('');
                $("#oddsunder").focus();
                return false;
            }

            if (isNaN(oddsmax) || oddsmax <= 0) {
                popupSite("Maximumbet_pp");
                $("#oddsmax").val('');
                $("#oddsmax").focus();
                return false;
            }
        }

        if (categoryId == 5) {

            if (isNaN(scorehome) || scorehome <= 0) {
                popupSite("ScoreHandicapHome_pp");
                $("#scorehome").val('');
                $("#scorehome").focus();
                return false;
            }

            if (isNaN(scoreaway) || scoreaway <= 0) {
                popupSite("ScoreHandicapAway_pp");
                $("#scoreaway").val('');
                $("#scoreaway").focus();
                return false;
            }

            if (isNaN(oddsexact) || oddsexact <= 0) {
                popupSite("OddsExact_pp");
                $("#oddsexact").val('');
                $("#oddsexact").focus();
                return false;
            }

            if (isNaN(oddsmax) || oddsmax <= 0) {
                alert("Maximumbet is required!");
                $("#oddsmax").val('');
                $("#oddsmax").focus();
                return false;
            }
        }
        $.ajax({
            type: 'POST',
            ulr: $(this).attr('action'),
            data: $(this).serialize(),
            complete: function() {
            },
            success: function(data) {
                if (data == "1") {
                    popupSite("NewBetSuccessfully");
                    $("#formbets")[0].reset();
                    return false;
                }
                if (data == "0") {
                    popupSite("CheckBalance");
                    return false;
                }

                if (data == "5") {
                    popupSite("NewBetFailed");
                    ;
                }

                if (data == "4") {
                    popupSite("NewBetFailed");
                }
            }
        });

    });
</script>